package onlinecalsys.client.view.gui;


 /****************************************************************/ 
 /*                      ShareAppointment	                            */ 
 /*                                                              */ 
 /****************************************************************/ 
 import java.awt.Component;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.Point;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import java.net.URL;

import javax.imageio.ImageIO;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.UIManager;
import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;

import onlinecalsys.client.view.View;
 /** 
  * Summary description for ShareAppointment 
  * 
  */ 
 public class ShareAppointment extends JFrame 
 { 
 	// Variables declaration 
 	private JLabel jLabelShareAppointmentID; 
 	private JLabel jLabelShareUser; 
 	private JTextField jTextFieldShareAppointmentID; 
 	private JTextField jTextFieldShareUser; 
 	private JButton jButtonShareAppointmentOK; 
 	private JPanel contentPaneAppointmentID; 
 	
 	private View view;
  
  
 	public ShareAppointment(View view) 
 	{ 
 		super(); 
 		this.view = view;
 		initializeComponent(); 
 		
 	// load frame logo
		BufferedImage image = null;
		try {
			URL u = this.getClass().getResource(
			"../../../../");
			File f = new File(u.getPath().replaceAll("bin/", "images/middle1.png"));
			System.out.println(f.getAbsolutePath());
			image = ImageIO.read(f);
			
			
		} catch (IOException e) {
			new Error("failed loading middle1.png");
		} catch (Exception e) {
			new Error("failed loading middle1.png");
		}
		this.setIconImage(image);
  
 		this.setVisible(true); 
 	} 
  
 	/** 
 	 * This method is called from within the constructor to initialize the form. 
 	 * WARNING: Do NOT modify this code. The content of this method is always regenerated 
 	 * by the Windows Form Designer. Otherwise, retrieving design might not work properly. 
 	 * Tip: If you must revise this method, please backup this GUI file for JFrameBuilder 
 	 * to retrieve your design properly in future, before revising this method. 
 	 */ 
 	private void initializeComponent() 
 	{ 
 		jLabelShareAppointmentID = new JLabel(); 
 		jLabelShareUser = new JLabel(); 
 		jTextFieldShareAppointmentID = new JTextField(); 
 		jTextFieldShareUser = new JTextField(); 
 		jButtonShareAppointmentOK = new JButton(); 
 		contentPaneAppointmentID = (JPanel)this.getContentPane(); 
  
 		// 
 		// jLabelShareAppointmentID 
 		// 
 		jLabelShareAppointmentID.setText("Appointment ID:"); 
 		// 
 		// jLabelShareUser 
 		// 
 		jLabelShareUser.setText("User:"); 
 		// 
 		// jTextFieldShareAppointmentID 
 		// 
 		jTextFieldShareAppointmentID.addActionListener(new ActionListener() { 
 			public void actionPerformed(ActionEvent e) 
 			{ 
 				jTextFieldShareAppointmentID_actionPerformed(e); 
 			} 
  
 		}); 
 		// 
 		// jTextFieldShareUser 
 		// 
 		jTextFieldShareUser.addActionListener(new ActionListener() { 
 			public void actionPerformed(ActionEvent e) 
 			{ 
 				jTextFieldShareUser_actionPerformed(e); 
 			} 
  
 		}); 
 		// 
 		// jButtonShareAppointmentOK 
 		// 
 		jButtonShareAppointmentOK.setText("OK"); 
 		jButtonShareAppointmentOK.addActionListener(new ActionListener() { 
 			public void actionPerformed(ActionEvent e) 
 			{ 
 				jButtonShareAppointmentOK_actionPerformed(e); 
 				
 			}

			
  
 		}); 
 		// 
 		// contentPaneAppointmentID 
 		// 
 		contentPaneAppointmentID.setLayout(null); 
 		contentPaneAppointmentID.setBorder(new TitledBorder("Share")); 
 		addComponent(contentPaneAppointmentID, jLabelShareAppointmentID, 19,31,82,18); 
 		addComponent(contentPaneAppointmentID, jLabelShareUser, 67,61,60,18); 
 		addComponent(contentPaneAppointmentID, jTextFieldShareAppointmentID, 100,30,100,22); 
 		addComponent(contentPaneAppointmentID, jTextFieldShareUser, 99,60,102,22); 
 		addComponent(contentPaneAppointmentID, jButtonShareAppointmentOK, 151,92,78,28); 
 		// 
 		// ShareAppointment 
 		// 
 		this.setTitle("ShareAppointment"); 
 		this.setLocation(new Point(80, 29)); 
 		this.setSize(new Dimension(250, 160)); 
 		this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 
 		this.setResizable(false); 
 	} 
  
 	/** Add Component Without a Layout Manager (Absolute Positioning) */ 
 	private void addComponent(Container container,Component c,int x,int y,int width,int height) 
 	{ 
 		c.setBounds(x,y,width,height); 
 		container.add(c); 
 	} 
  
 	// 
 	// TODO: Add any appropriate code in the following Event Handling Methods 
 	// 
 	private void jTextFieldShareAppointmentID_actionPerformed(ActionEvent e) 
 	{ 
 		System.out.println("\njTextFieldShareAppointmentID_actionPerformed(ActionEvent e) called."); 
 		// TODO: Add any handling code here 
  
 	} 
  
 	private void jTextFieldShareUser_actionPerformed(ActionEvent e) 
 	{ 
 		System.out.println("\njTextFieldShareUser_actionPerformed(ActionEvent e) called."); 
 		// TODO: Add any handling code here 
  
 	} 
  
 	private void jButtonShareAppointmentOK_actionPerformed(ActionEvent e) 
 	{ 
 		try {
 			String idInput = jTextFieldShareAppointmentID.getText();
 			int id = Integer.valueOf(idInput);
 			String username = jTextFieldShareUser.getText().trim();
 			System.out.println(idInput);
 			System.out.println(username);
 			if(username.equals("")) {
 				new Error("Sorry the Username is empty");
 			} else {
 				boolean status = view.shareAppointment(id, username); 
 				if(status) {
 					dispose();
 				}
 				
 			}
			
		} catch (Exception e2) {
			new Error("Sorry the Id input has to be a number");
		}
  
 	} 
  
 	// 
 	// TODO: Add any method code to meet your needs in the following area 
 	// 
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
  
   
  
 //============================= Testing ================================// 
 //=                                                                    =// 
 //= The following main method is just for testing this class you built.=// 
 //= After testing,you may simply delete it.                            =// 
 //======================================================================// 
// 	public static void main(String[] args) 
// 	{ 
// 		JFrame.setDefaultLookAndFeelDecorated(true); 
// 		JDialog.setDefaultLookAndFeelDecorated(true); 
// 		try 
// 		{ 
// 			UIManager.setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel"); 
// 		} 
// 		catch (Exception ex) 
// 		{ 
// 			System.out.println("Failed loading L&F: "); 
// 			System.out.println(ex); 
// 		} 
// 		new ShareAppointment(); 
// 	} 
 //= End of Testing = 
  
  
 } 
  
 